<template>
  <div class="tower-container">
    <div class="tower-info">
      <div class="tower-online">
        <dv-box title="塔吊状态">
          <div class="online-info">
            <div class="item">
              <p>塔吊数量</p>
              <h3>{{online.devicetot}}<span>台</span></h3>
            </div>
            <div class="item">
              <p>运行状态</p>
              <h3>{{online.current}}<span>在线</span></h3>
            </div>
            <div class="item">
              <p>今日总吊次</p>
              <h3>{{online.loadtimes}}<span>次</span></h3>
            </div>
            <div class="item">
              <p>今日总吊重</p>
              <h3>{{online.loadtot}}<span>t</span></h3>
            </div>
          </div>
        </dv-box>
      </div>
      <div class="tower-real">
        <dv-box title="塔吊实时数据">
          <div class="real-box">
            <div class="item" v-for="item in realList" :key="item.id">
              <div class="hd">{{item.snname}} <el-tag size="mini" effect="dark" type="success" style="margin-left: 10px;">在线</el-tag></div>
              <div class="bd">
                <p><span>回转角度：</span>{{Number(item.angle).toFixed(2) || 0}}°</p>
                <p><span>幅度：</span>{{Number(item.radius).toFixed(2) || 0}}m</p>
                <p><span>吊钩高度：</span>{{Number(item.height).toFixed(2) || 0}}m</p>
                <p><span>吊重：</span>{{ Number(item.vcload).toFixed(2) || 0}}t</p>
                <p><span>力矩百分比：</span>{{ Number(item.percent).toFixed(2) || 0}}%</p>
                <p><span>安全吊重：</span>{{ Number(item.safeload).toFixed(2) || 0}}t</p>
                <p><span>风速：</span>{{ Number(item.windspeed).toFixed(2) || 0}}m/s</p>
              </div>
            </div>
          </div>
        </dv-box>
      </div>
    </div>

    <div class="tower-history">
      <dv-box title="塔吊历史数据" :roption="{show:true,btn:'clickTime'}" @clickTime="clickDate">
        <dv-scroll-board :config="tableConfig" style="width:100%;height:100%" />
      </dv-box>
    </div>
  </div>
</template>

<script>
import dvBox from "@/components/datav/dv-box.vue";
import moment from "moment"
export default {
  props:{
    id:{
      type:Number|String,
      default:''
    }
  },
  components:{
    dvBox
  },
  data() {
    return {
      realList:[],
      tableConfig:{},
      online:{
        devicetot:0,
        current:0,
        loadtot:0,
        loadtimes:0
      }
    }
  },
  created() {
    this.$datav.getTowerOnline({projectid:this.id}).then(res => {
      if(res.code == 0 && res.data) {
        this.online.devicetot = res.data.devicetot
        this.online.current = res.data.current
        this.online.loadtot = res.data.loadtot ? res.data.loadtot.toFixed(2) : 0
        this.online.loadtimes = res.data.loadtimes
      }
    })
    this.getTowerData()
    this.$datav.getTowerReal({projectid:this.id,today:moment().format('YYYY-MM-DD')}).then(res => {
      if(res.code == 0) this.realList = res.data
    })
  },
  methods:{
    clickDate(val){
        this.getTowerData(val[0],val[1])
    },
    getTowerData(s,e){
        this.$datav.getTowerHistory({projectid:this.id,start:s??'',end:e??''}).then(res => {
            let arr = []
            res.data.content.map(item => {
                arr.push(
                    [item.snname,item.starttime,item.endtime,formatDuring(item.timeduration),item.maxradius.toFixed(2),item.minradius.toFixed(2),item.maxload.toFixed(2),item.safeload.toFixed(2),item.maxwindspeed.toFixed(2),item.minwindspeed.toFixed(2)]
                )
            })
            this.tableConfig = {
                header: ['名称', '开始作业时间', '结束作业时间','有效作业时长', '最大幅度(m)', '最小幅度(m)','平均吊重(t)', '安全吊重(t)', '最大风速(m/s)', '最小风速(m/s)'],
                index: true,
                rowNum:8,
                headerHeight:40,
                columnWidth:[80,150,220,220,180,180,180,180,180,200,200],
                headerBGC:'#F2F3F5',
                oddRowBGC:'rgba(0,0,0,0)',
                evenRowBGC:'rgba(0,0,0,0)',
                data:arr
            }
        })
    }
  }
}
function formatDuring(value){
  let hours = parseInt(value % (60 * 60 * 24) / (60 * 60));
  let minutes = parseInt(value % (60 * 60) / ( 60));
  let seconds = value % (60);
  if (hours < 10) {
    hours = '0' + hours
  }
  if (minutes < 10) {
    minutes = '0' + minutes
  }
  if (seconds < 10) {
    seconds = '0' + seconds
  }
  return hours + ":" + minutes + ":" + seconds;
}
</script>

<style lang="scss" scoped>
.tower-container{
  margin-top: 24px;
  width: 100%;
  height: calc(100% - 60px);
  min-height: 676px;
  display: grid;
  grid-template-columns: 100%;
  grid-template-rows: repeat(2, 1fr);
  grid-gap: 24px;

  .tower-info{
    display: flex;
    justify-content: space-between;
    overflow: hidden;

    .tower-online{
      width: 570px;
      .online-info{
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        height: 100%;
        min-height: 274px;
        .item{
          width: 260px;
          height: 40%;
          background: url("../../../../assets/images/ov-energy.png") 0 0 no-repeat;
          background-size: 100% 100%;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          margin-bottom: 20px;
          p{
            margin: 0 0 10px;
            font-size: 16px;
            color: #000000 !important;
          }
          h3{
            font-size: 36px;
            color: rgb(255, 87, 2) !important;
            text-shadow: 0px 0px 8px rgba(255,119,52,0.5000);
            margin: 0;
            span{
              font-size: 16px;
              margin-left: 4px;
            }
          }
          &:nth-child(3),&:nth-child(4){
            margin-bottom: 20px;
          }
        }
      }
    }
    .tower-real{
      flex: 1;
      margin-left: 30px;

      .real-box{
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        padding-top: 20px;
        min-height: 274px;
        height: 350px;
        overflow-x: hidden;
        .item{
          width: 48%;
          background: rgba(255,255,255,0.1);
          padding: 15px;
          height: 120px;
          border-radius: 4px;
          color: rgba(0, 0, 0, 0.8) !important;
          margin-bottom: 40px;
          .hd{
            display: flex;
            align-items: center;
            font-size: 20px;
          }
          .bd{
            display: flex;
            flex-wrap: wrap;
            p{
              width: 25%;
              margin: 15px 0 0;
              font-size: 16px;
              span{
                color: rgba(0, 0, 0, 0.5) !important;
                // color: rgba(255,255,255,.5);
                font-size: 14px;
              }
            }
          }
        }
      }
    }
  }
}
@include dvScroll
</style>